package router

import (
	"ci-control-backend/common/httpx"
	"ci-control-backend/controller"
	"ci-control-backend/middleware"
	"github.com/gin-gonic/gin"
)

var userController *controller.UserController
var userManageController *controller.UserManageController

func init() {
	userController = new(controller.UserController)
	userManageController = new(controller.UserManageController)
}

func SetupUserRoutes(r *gin.Engine) {
	// 以下API无需验证
	noAuth := r.Group("/user")
	noAuth.Use()
	{
		noAuth.POST("/login", httpx.Controller(userController.Login))
	}
	// 以下API需要用户权限
	userAuth := r.Group("/user")
	userAuth.Use(httpx.Middleware(middleware.UserAuth))
	{
		userAuth.GET("/myInfo", httpx.Controller(userController.MyInfo))
		userAuth.POST("/updateMyInfo", httpx.Controller(userController.UpdateMyInfo))
		userAuth.POST("/updatePassword", httpx.Controller(userController.UpdatePassword))
		userAuth.GET("/list", httpx.Controller(userController.GetUserList))
		userAuth.GET("/getUserInfo", httpx.Controller(userController.GetUserInfo))
	}
	// 以下API需要管理员权限
	adminAuth := r.Group("/admin/user")
	adminAuth.Use(httpx.Middleware(middleware.AdminAuth))
	{
		adminAuth.POST("/newUser", httpx.Controller(userManageController.NewUser))
		adminAuth.POST("/updateUser", httpx.Controller(userManageController.UpdateUser))
		adminAuth.GET("/restPassword", httpx.Controller(userManageController.RestPassword))
		adminAuth.GET("/deleteUser", httpx.Controller(userManageController.DeleteUser))
	}
}
